package cst.a112gxl.TeacherPlatform112gxl.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import java.util.ArrayList;
import java.util.List;

import cst.a112gxl.TeacherPlatform112gxl.R;

import cst.a112gxl.TeacherPlatform112gxl.fragment.CollectFragment;
import cst.a112gxl.TeacherPlatform112gxl.fragment.FFragment;

public class MeActivity extends AppCompatActivity {
    private List<Fragment> listFragment;
    private FragmentPagerAdapter fragmentPagerAdapter;
    private ViewPager viewPager;
    private String mod;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_me);
        mod = getIntent().getStringExtra("mod");
        init();
        initFragment();
    }
    private void initFragment() {
        listFragment=new ArrayList<Fragment>();
        if (mod.equals("collect")){
            listFragment.add(new CollectFragment());
        }else if(mod.equals("focus")) {
            listFragment.add(new FFragment());
        }

        fragmentPagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return listFragment.get(position);
            }

            @Override
            public int getCount() {
                return listFragment.size();
            }
        };

        viewPager.setAdapter(fragmentPagerAdapter);
        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                viewPager.setCurrentItem(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }


    private void init() {
        viewPager = (ViewPager) findViewById(R.id.viewPager);
    }

}
